package zust.se.ssm.mapper;

import org.apache.ibatis.annotations.*;
import zust.se.ssm.model.Contacts;

import java.util.List;

/**
 * 
 * @author czg
 * @since 2022/12/14 14:58
 */
public interface ContactsMapper {
    @Select("select * from contacts where id=#{id}")
    public Contacts getById(@Param("id") int contactsId);
    @Select("select * from contacts")
    public List<Contacts> allContacts();

    @Select("select * from contacts where `name` like CONCAT('%',#{name},'%')")
    List<Contacts> searchByName(@Param("name") String name);
    @Select("select * from contacts where user_id=#{userId} and `name` like CONCAT('%',#{name},'%')")
    List<Contacts> searchByUserIDAndName(@Param("name") String name,@Param("userId")int userId);

    @Update("update contacts set name=#{name},address=#{address},mobile=#{mobile} where id=#{id}")
    void updateContacts(Contacts contacts);
    @Delete("delete from contacts where id=#{id}")
    void deleteById(int id);

    @Insert("insert into contacts (name,address,mobile,user_id) values(#{name},#{address},#{mobile},#{userId})")
    void add(Contacts contacts);
    @Select("select * from contacts where user_id=#{userId}")
    List<Contacts> getUserContacts(Integer userId);
}
